<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/12/20
 * Time: 14:18
 */

/**
 * 根据银行编码生成银行选择列表
 *
 * @param $code 银行编码
 * @return string html内容
 */
function generate_bank_name_by_code($code)
{
    //获取所有的银行
    $bankList = M("Bank")->select();

    //html
    $html = "<option value=''" . ($code == '' ? "selected" : "") . ">请选择……</option>";

    foreach ($bankList as $bank)
    {
        $html .= "<option value='" . $bank["bank_code"] . "'" . ($code == $bank["bank_code"] ? "selected" : "") . ">" . $bank["bank_name"] . "</option>";
    }

    return $html;
}

function generate_bank_name_by_user()
{
    $bankList = M("MemberBankCard")
        ->alias("m")
        ->join("LEFT JOIN Bank AS b ON b.bank_code=m.bank")
        ->where(array(
            "member_id" => $_SESSION["userinfo"]["id"],
            "deleted" => 0
        ))
        ->field("m.*,b.bank_name")
        ->select();

    //html
    $html = "";

    foreach ($bankList as $bank)
    {
        if ($bank["number"])
        {
            $html .= "<option value='" . $bank["id"] . "'"
                . ($bank["is_default"] == 1 ? "selected" : "") . ">"
                . $bank["number"] . "&nbsp;&nbsp;&nbsp;&nbsp;"
                . $bank["bank_name"] . "</option>";
        }

    }

    return $html;
}


//输出订单类型
function getagentlevel($type)
{

        switch ($type)
        {
            case "0":
                return "厂家";
            case "1":
                return "一级代理";
            case "2":
                return "二级代理";
            case "3":
                return "三级代理";
            case "4":
                return "四级代理";
            case "5":
                return "五级代理";
            case "6":
                return "六级代理";
            case "7":
                return "七级代理";
            case "8":
                return "八级代理";
            case "9":
                return "九级代理";
            case "10":
                return "十级代理";
            default:
                return "无";
        }
}